//
//  DYUpdatePasswordView.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/21.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYUpdatePasswordView.h"

@interface DYUpdatePasswordView ()

@property (nonatomic,strong)DYUpdatePasswordChildView *oldPasswordView;
@property (nonatomic,strong)DYUpdatePasswordChildView *newsPasswordView;
@property (nonatomic,strong)UIButton *submitButton;

@end

@implementation DYUpdatePasswordView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    self.oldPasswordView=({
        DYUpdatePasswordChildView *view=[[DYUpdatePasswordChildView alloc]init];
        view.titleLabel.text=@"原登录密码";
        view.textField.placeholder=@"请输入原登录密码";
        [view.textField setValue:[UIColor xhq_assist] forKeyPath:@"_placeholderLabel.textColor"];
        view.seeButton.hidden=YES;
        view;
    });
    
    
    self.newsPasswordView=({
        DYUpdatePasswordChildView *view=[[DYUpdatePasswordChildView alloc]init];
        view.titleLabel.text=@"新登录密码";
        view.textField.placeholder=@"请输入新登录密码";
        [view.textField setValue:[UIColor xhq_assist] forKeyPath:@"_placeholderLabel.textColor"];
        view;
    });
    
    self.submitButton =({
        UIButton * button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:[UIColor xhq_base] action:@selector(submitButtonClick) target:self title:@"保存修改" image:@"icon_login" font:17 textColor:WhiteColor];
        [button xhq_cornerRadius:BILIHEIGHT(19)];
        button;
    });
    
    [self addSubview:self.oldPasswordView];
    [self addSubview:self.newsPasswordView];
    [self addSubview:self.submitButton];
    
    
    [self.oldPasswordView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(10));
        make.right.equalTo(BILIWIDTH(-10));
        make.top.equalTo(BILIHEIGHT(10));
        make.height.equalTo(BILIHEIGHT(58));
    }];
    
    [self.newsPasswordView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.oldPasswordView.bottom);
        make.left.right.height.equalTo(self.oldPasswordView);
    }];
    
    [self.submitButton makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.newsPasswordView.bottom).offset(BILIHEIGHT(145));
        make.right.equalTo(BILIWIDTH(-10));
        make.size.equalTo(CGSizeMake(BILIWIDTH(132), BILIHEIGHT(38)));
    }];
    
    [self.submitButton placeImageTitlePosition: ZYButtonImagePositionRight space:BILIWIDTH(10)];
    
}
-(void)submitButtonClick
{
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end


@implementation DYUpdatePasswordChildView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}
-(void)initView
{
    
    self.titleLabel=({
        UILabel *label=[Utils labelWithTitleFontSize:12 textColor:[UIColor xhq_content] alignment:0];
        label;
    });
    
    self.textField = ({
        UITextField *text=[[UITextField alloc]init];
        text.font=kFont(14);
        text.autocorrectionType = UITextAutocorrectionTypeNo;
        text.secureTextEntry=YES;
        text;
    });
    
    self.seeButton=({
        UIButton *button=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:WhiteColor action:@selector(seeButtonClick) target:self title:nil image:@"icon_mm_close" font:15 textColor:[UIColor xhq_base]];
        [button setImage:IMG(@"icon_mm_open") forState:UIControlStateSelected];
        button;
    });
    
    self.line =({
        UILabel *line=[UILabel xhq_lineLabel];
        line;
    });
    
    [self addSubview:self.titleLabel];
    [self addSubview:self.textField];
    [self addSubview:self.seeButton];
    [self addSubview:self.line];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(BILIWIDTH(0));
        make.top.equalTo(BILIHEIGHT(10));
    }];
    
    [self.textField makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.height.equalTo(BILIHEIGHT(30));
        make.left.equalTo(BILIWIDTH(0));
        make.right.equalTo(BILIWIDTH(-70));
    }];
    
    [self.seeButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(BILIWIDTH(0));
        make.centerY.equalTo(self);
    }];
    
    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(0);
        make.bottom.equalTo(0);
        make.height.equalTo(BILIWIDTH(0.7));
    }];
    
    
}

-(void)seeButtonClick
{
    self.seeButton.selected=!self.seeButton.selected;
    
    if (self.seeButton.selected) {
        self.textField.secureTextEntry=NO;
    }else{
        self.textField.secureTextEntry=YES;
    }
}
@end
